package com.yunysha.struts.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.yunysha.constants.YunyshaConstants;
import com.yunysha.controller.YunyshaController;
import com.yunysha.struts.actionform.UserMasterForm;

public class UserMasterSaveAction extends Action {

	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		String forward = null;
		
		UserMasterForm uForm = (UserMasterForm) form;
		
		YunyshaController yController = new YunyshaController();
		
		boolean isSuccess = yController.insertOrUpdateUserDetails(uForm);
		
		uForm.setIsCreate("N");
		
		if(isSuccess){
			forward = YunyshaConstants.SUCCESS;
			uForm.setIsError("N");
			uForm.setErrorMessage("User details saved successfully.");
		} else {
			forward = YunyshaConstants.FAILURE;
			uForm.setIsError("Y");
			uForm.setErrorMessage("User details could not be saved.");
		}
		
		return mapping.findForward(forward);
	}

}
